package com.zhoug.common3.utils;

import android.app.ActivityManager;
import android.content.Context;

import java.util.List;

/**
 * 系统服务工具
 * @Author 35574
 * @Date 2021/3/22
 * @Description
 */
public class ServiceUtils {

    /**
     * 获取ActivityManager
     * @param context
     * @return
     */
    public static ActivityManager getActivityManager(Context context) {
        return (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
    }


    /**
     * 获取当前进程名字
     * @param context
     * @return
     */
    public static String getCurrentProcessName(Context context) {
        List<ActivityManager.RunningAppProcessInfo> runningApps = getActivityManager(context).getRunningAppProcesses();
        if (runningApps == null) {
            return null;
        }
        int pid = android.os.Process.myPid();
        for (ActivityManager.RunningAppProcessInfo procInfo : runningApps) {
            if (procInfo.pid == pid) {
                return procInfo.processName;
            }
        }
        return null;
    }




}
